package com.ly.mpayment.rest.system;


import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;

import com.ly.mpayment.core.util.CookieRedis;
import com.ly.mpayment.rest.up.hebao.HeBaoRest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ly.mpayment.core.util.JsonUtils;
import com.ly.mpayment.core.util.ResultMessage;
import com.ly.mpayment.persist.service.upshopinfo.IUpShopInfoService;
import com.ly.mpayment.persist.service.user.IUserService;
import com.ly.mpayment.rest.AbsRest;

import net.sf.json.JSONObject;

@Component
@Path("system/upshopinfo/")
public class UpShopInfoRest extends AbsRest {

	@Autowired
	IUserService userService;

	@Autowired
	IUpShopInfoService shopInfoService;

	@Path("findOneShopInfo")
	@POST
	public String findOneShopInfo(String data,@Context HttpServletRequest request){
		String result = this.validationParameter(data, request, userService, "upshopuuid");
		if(result == null){
			JSONObject json = JsonUtils.converToJson(data);
			return ResultMessage.getSucceed( JsonUtils.excludes(this.shopInfoService.findById(json.getString("upshopuuid")),
					new String[]{"errorCodesForUseruuid","","lastlogintime","token","usertype","userstatus","password"}));
		}
		return result;
	}

	@Path("findByProvince")
	@POST
	public String findByProvince(String data,@Context HttpServletRequest request){
		String result = this.validationParameter(data, request, userService, "provinceuuid");
		if(result == null){
			JSONObject json = JsonUtils.converToJson(data);
			return ResultMessage.getSucceed( JsonUtils.jsonArrayToJson(this.shopInfoService.findAllByProvince(json.getString("provinceuuid")),
					new String[]{"errorCodesForUseruuid","provincialInformation","upshopip","upkey","shopnum","createtime","status","upshopbalance",
							"modifytime","phonenum","password","userstatus","remark","wechatid","createtime","lastlogintime","usertype","token","","",""}));
		}
		return result;
	}

	@Path("findAllUpShopInfo")
	@POST
	public String findAllUpShopInfo(String data,@Context HttpServletRequest request){
		String result = this.validationParameter(data, request, userService, "");
		if(result == null){
			return ResultMessage.getSucceed( JsonUtils.jsonArrayToJson(this.shopInfoService.findAllByProvince(),
					new String[]{"errorCodesForUseruuid","provincialInformation","upshopip","upkey","shopnum","createtime","status","upshopbalance",
							"modifytime","phonenum","password","userstatus","remark","wechatid","createtime","lastlogintime","usertype","token","orderStatusAddress","orderCallAddress","orderCommitAddress","queryBalanceAddress"}));
		}
		return result;
	}

	/**
	 * 更新是否转人工状态
	 * @param data
	 * @param request
	 * @return
	 */
	@POST
	@Path("updateArtificial")
	public  String updateArtificial(String data, @Context HttpServletRequest request) {
		String result = this.validationParameter(data, request, userService, "upshopuuid","artificial");
		if(result == null){
			JSONObject json = JsonUtils.converToJson(data);
			return this.shopInfoService.updateArtificial(json);
		}
		return result;
	}

	/**
	 * 是否压单 1 转压单 0 不压单
	 * @param data
	 * @param request
	 * @return
	 */
	@POST
	@Path("updatePressOrder")
	public  String updatePressOrder(String data, @Context HttpServletRequest request) {
		String result = this.validationParameter(data, request, userService, "upshopuuid","pressOrder");
		if(result == null){
			JSONObject json = JsonUtils.converToJson(data);
			return this.shopInfoService.updatePressOrder(json);
		}
		return result;
	}

	@POST
	@Path("changeQuerySwitch")
	public  String changeQuerySwitch(String data, @Context HttpServletRequest request) {
		String result = this.validationParameter(data, request, userService, "upshopuuid","querySwitch");
		if(result == null){
			JSONObject json = JsonUtils.converToJson(data);
			return this.shopInfoService.updateQuerySwitch(json);
		}
		return result;
	}

	@POST
	@Path("noticeUpSwitch")
	public  String noticeBalanceSwitch(String data, @Context HttpServletRequest request) {
		String result = this.validationParameter(data, request, userService, "upshopuuid","noticeSwitch");
		if(result == null){
			JSONObject json = JsonUtils.converToJson(data);
			return this.shopInfoService.updateUpSwitch(json);
		}
		return result;
	}

	@Autowired
	HeBaoRest heBaoRest;

	@POST
	@Path("getRefreshTop")
	public  String getRefreshTop(String data, @Context HttpServletRequest request) {
		String result = this.validationParameter(data, request, userService, "upshopuuid","querySwitch");
		if(result == null){
			JSONObject json = JsonUtils.converToJson(data);
			return ResultMessage.getSucceed(heBaoRest.heartYd(CookieRedis.get("ChinaMobileHeBaoToken")));
		}
		return result;
	}

}

